Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P-chain - Memo field zeroed post Durango #2607

Merged
merged 18 commits into from
Jan 19, 2024

Conversation

abi87
Copy link
Contributor

@abi87 abi87 commented Jan 13, 2024

Why this should be merged

Post Durango we're going to enforce the Memo field is zero for any P-chain tx

How this works

Introduced extra checks. No changes to wallets and APIs yet. We'll revisit it post Durango activation

How this was tested

CI

@@ -65,3 +65,20 @@ func (t *BaseTx) Verify(ctx *snow.Context) error {
return nil
}
}

func VerifyMemoFieldLength(memo types.JSONByteSlice, isDurangoActive bool) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a different method rather than extending SyntacticVerify with config and chainTIme. We can revisit this choice down the line, in case other syntactic checks will depend on the specific fork used

@StephenButtolph StephenButtolph added this to the v1.10.19 milestone Jan 16, 2024
@StephenButtolph StephenButtolph changed the base branch from dev to master January 18, 2024 21:00
Copy link
Contributor

@StephenButtolph StephenButtolph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some tests that fail verification because of non-empty memo fields?

vms/components/avax/base_tx.go Outdated Show resolved Hide resolved
vms/platformvm/txs/executor/staker_tx_verification.go Outdated Show resolved Hide resolved
vms/platformvm/txs/executor/standard_tx_executor.go Outdated Show resolved Hide resolved
vms/platformvm/txs/unsigned_tx.go Outdated Show resolved Hide resolved
@abi87 abi87 requested a review from StephenButtolph January 19, 2024 13:35
@StephenButtolph StephenButtolph added the Durango durango fork label Jan 19, 2024
Copy link
Contributor

@marun marun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see obvious errors, but I'm also not sure how to distill this much copy-pasta test code to be able to catch mistakes. I would highly recommend using table-driven testing, a set of reusable test data, and shared helkpers for this kind of testing to simplify both review and maintenance.

@@ -1003,7 +1041,951 @@ func TestStandardTxExecutorDurangoAddValidator(t *testing.T) {
require.Equal(endTime, val.EndTime)
}

func TestDurangoStandardTxExecutorAddPermissionlessValidatorTx(t *testing.T) {
require := require.New(t)
env := newEnvironment(t, true /*=postBanff*/, true /*=postCortina*/, true /*=postDurango*/)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(No action required) Maybe use structs where naming of variables is desired (also good for optional parameters):

env := newEnvironment(t, envConfig{
        postBanff:   true,
        postCortina: true,
        postDurango: true,
    },
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept this aligned with other tests. However booleans are not great. In #2169 I have cleaned it up and replace the booleans with a fork enum. I'd defer to cleanup to that PR

env.ctx.Lock.Lock()
defer func() {
require.NoError(shutdownEnvironment(env))
env.ctx.Lock.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok that a failure to shutdown the environment without error won't release the lock? If not, maybe shutdownEnvironment would be a better place to ensure lock release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it does not really matter in this case, since this happens at the very end of the test. But this is something that can be fixed for all tests. #2491 by @dhrubabasu fixes this concern I believe.

uint64(endTime.Unix()),
nodeID,
// Build the AddValidatorTx
ins, unstakedOuts, stakedOuts, signers, err := env.utxosHandler.Spend(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(No action required) Maybe extract into a helper?

}},
Subnet: testSubnet1.TxID,
AssetID: ids.GenerateTestID(),
InitialSupply: 10,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(No action required) Lots of magic numbers here. Even in tests, using descriptive variable names can be helpful to declare your intent (or where that is too much at least defining a struct configured with a bunch of magic numbers with an appropriately descriptive name).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These numbers don't really matter here, they're just enough to pass validation.
The whole point is to showcase validation around Memo field. But to get a fully formed tx I have specified other attributes.
Perhabs I shoud mark these values as dummy...? Or even better we should probably have a single UT per transactions, carriying out all the relevant validations per fork


func VerifyMemoFieldLength(memo types.JSONByteSlice, isDurangoActive bool) error {
if !isDurangoActive {
return nil // already validated in SyntacticVerify
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil // already validated in SyntacticVerify
// SyntacticVerify validates this field post-Durango
return nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -728,6 +761,10 @@ func verifyTransferSubnetOwnershipTx(
return err
}

if err := avax.VerifyMemoFieldLength(tx.Memo, true /*isDurangoActive*/); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*isDurangoActive*/); err != nil {
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*=isDurangoActive*/); err != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -512,6 +550,10 @@ func (e *StandardTxExecutor) BaseTx(tx *txs.BaseTx) error {
return err
}

if err := avax.VerifyMemoFieldLength(tx.Memo, true /*isDurangoActive*/); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*isDurangoActive*/); err != nil {
if err := avax.VerifyMemoFieldLength(tx.Memo, true /*=isDurangoActive*/); err != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -54,13 +54,20 @@ func (e *StandardTxExecutor) CreateChainTx(tx *txs.CreateChainTx) error {
return err
}

var (
timestamp = e.State.GetTimestamp()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: timestamp -> currentTimestamp to match the usage in other funcs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -98,8 +105,15 @@ func (e *StandardTxExecutor) CreateSubnetTx(tx *txs.CreateSubnetTx) error {
return err
}

var (
timestamp = e.State.GetTimestamp()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: timestamp -> currentTimestamp to match the usage in other funcs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@abi87 abi87 requested a review from dhrubabasu January 19, 2024 17:41
@StephenButtolph StephenButtolph added this pull request to the merge queue Jan 19, 2024
Merged via the queue into master with commit 3d4feed Jan 19, 2024
17 checks passed
@StephenButtolph StephenButtolph deleted the p-chain-no-memo-field-durango branch January 19, 2024 22:47
chand1012 pushed a commit to multisig-labs/avalanchego that referenced this pull request Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Durango durango fork
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants